package 优先算法.二分查找.搜索插入位置;

/**
 * https://leetcode.cn/problems/search-insert-position/description/
 */
public class Main {
    public static void main(String[] args) {
        Solution so =new Solution();
        int[] arr = {1,3,5,6};
        int rel = so.searchInsert(arr,7);
        System.out.println(rel);
    }
}
class Solution {
    public int searchInsert(int[] nums, int target) {
        int left = 0,right = nums.length - 1;

        if(nums[right] < target){
            return right + 1;
        }
        while(left < right){
            int mid = left + (right - left)/2;
            if(nums[mid] < target){
                left = mid + 1;
            }
            if(nums[mid] >= target){
                right = mid;
            }
        }
        return left;
    }
}